<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class Lock extends Model
{
    protected $table = 'xfy_locks';


    public static function genQrcode($name){
        self::delQrcode($name);

        $file = 'locks/'.md5($name).'.png';
        $filePath = public_path($file);
        QrCode::encoding('UTF-8')->format('png')->size(250)->margin(1)->generate($name,$filePath);
        return url($file);
    }

    public static function delQrcode($name){
        $file = md5($name).'.png';
        $filePath = public_path('locks/'.$file);
        if (is_file($filePath)) {
            unlink($filePath);
        }
    }
}